package com.zhj.network.Url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @PackageName:com.zhj.network.Url
 * @ClassName:UrlDown
 * @auter: 朱慧杰
 * @date:2020/7/21 0021 14:44
 **/
public class UrlDown {

    public static void main(String[] args) throws Exception {
        // 下载地址
        URL url = new URL("https://p1.music.126.net/I5lkTSaZttAmas_0ol6RSg==/109951165154760220.jpg");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        InputStream inputStream = connection.getInputStream();

        FileOutputStream fos = new FileOutputStream("wyy.jpg");

        byte[] buffer = new byte[1024];
        int len;
        while ((len = inputStream.read(buffer))!=-1) {
            fos.write(buffer, 0, len);
        }

        fos.close();
        inputStream.close();
        connection.disconnect();
    }

}
